using CSharpFactory.ParserFiles;
using CSharpFactory.Semantics;

namespace CSharpFactory.ProjectModel
{
    // ==================================================================================
    /// <summary>
    /// This abstract class represents a type cast operator expression.
    /// </summary>
    // ==================================================================================
    public sealed class TypeCastOperator : UnaryOperator
    {
        #region Private fields

        private TypeReference _Type;

        #endregion

        #region Lifecycle methods

        // --------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new operator expression.
        /// </summary>
        /// <param name="token">Token providing position information.</param>
        /// <param name="parser">Parser instance creating this element.</param>
        // --------------------------------------------------------------------------------
        public TypeCastOperator(Token token, CSharpSyntaxParser parser)
            : base(token, parser)
        {
        }

        #endregion

        #region Public properties

        // --------------------------------------------------------------------------------
        /// <summary>
        /// Gets or sets the type of this cast operator.
        /// </summary>
        // --------------------------------------------------------------------------------
        public TypeReference Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        #endregion

        #region TypeResolution

        // --------------------------------------------------------------------------------
        /// <summary>
        /// Resolves all unresolved type references.
        /// </summary>
        /// <param name="contextType">Type of resolution context.</param>
        /// <param name="declarationScope">Current type declaration context.</param>
        /// <param name="parameterScope">Current type parameter declaration scope.</param>
        // --------------------------------------------------------------------------------
        public override void ResolveTypeReferences(ResolutionContext contextType,
          ITypeDeclarationScope declarationScope,
          ITypeParameterScope parameterScope)
        {
            base.ResolveTypeReferences(contextType, declarationScope, parameterScope);
            if (_Type != null)
            {
                _Type.ResolveTypeReferences(contextType, declarationScope, parameterScope);
            }
        }

        #endregion

    }
}